// pages/selectIdentity/selectIdentity.js
const app = getApp();
Page({

  /**
   * 页面的初始数据
   */
  data: {
    p1: 'https://www.zhibohome.net/images/invite/jsxz_zrbg.png',
    // p2: 'https://www.zhibohome.net/images/sq_bg1.png',
    p3: 'https://www.zhibohome.net/images/invite/jsxz_zbbg.png',

    show_model: false,
    identity: null,

    token: null,

  },
  click_back(){
    wx.redirectTo({
      url: '../recruit/index/index'
    })
  },
  sel_hz: function() {
    this.setData({
      p1: 'https://www.zhibohome.net/images/invite/jsxz_zrbgax.png',
      // p2: 'https://www.zhibohome.net/images/sq_bg1.png',
      p3: 'https://www.zhibohome.net/images/invite/jsxz_zbbg.png',

      show_model: true,
      identity: "会长",
    })

  },
  sel_gly: function() {
    this.setData({
      p1: 'https://www.zhibohome.net/images/invite/jsxz_zrbg.png',
      // p2: 'https://www.zhibohome.net/images/selectIdentity/selected.png',
      p3: 'https://www.zhibohome.net/images/invite/jsxz_zrbg.png',

      show_model: true,
      identity: "管理员",
    })
  },
  sel_zb: function() {
    this.setData({
      p1: 'https://www.zhibohome.net/images/invite/jsxz_zrbg.png',
      // p2: 'https://www.zhibohome.net/images/sq_bg1.png',
      p3: 'https://www.zhibohome.net/images/invite/jsxz_zbbgax.png',

      show_model: true,
      identity: "主播",
    })
  },
  sure: function() {
    var that = this;
    switch (this.data.identity) {
      case "会长":
        var role = 1
        // console.log("我是会长")

        break;
      case "主播":
        var role = 2
        // console.log("我是主播")

        break;
      case "管理员":
        var role = 3
        // console.log("我是管理员")

        break;
    }
    wx.request({
      method: 'POST',
      url: app.globalData.url + 'api/common/add/info',
      data: {
        token: that.data.token,
        role: role,
      },
      success: function(e) {
        console.log(e)
        app.register_info.register_role=role;
        wx.setStorageSync('reg_register_role', that.data.role);
        that.get_userInfo();
        if (role==1){
          wx.reLaunch({
            // url: '../bindingGuild/index/index?skip=true',
            url: '../recruit/index/index?flag_first=true',
          })
        }else if(role==2){
          wx.reLaunch({
            url: '../resume/uploadResume/uploadResume?flag_first=true',
          })
        }else{}
        
      }
    })
  },
  cancel: function() {
    this.setData({
      show_model: false,
    })
  },
  //用户注册好，更新时间
  updateTime() {
    wx.request({
      method: "POST",
      url: app.globalData.url + 'api/user/update/logintime',
      data: {
        token: wx.getStorageSync('token'),
        from: "WxMiNi",
      },
      success: function (e) {
        //  console.log(e)
      }
    })
  },
  //get_userInfo
  get_userInfo(){
    let that = this;
    wx.request({
      url: app.globalData.url + 'api/common/register/info',
      data: {
        token: that.data.token,
      },
      method: 'POST',
      success: function(e) {
        console.log(e)
        var register_info = e.data.data.register_info;
        console.log(register_info)

        //token
        app.globalData.token = that.data.token;
        wx.setStorageSync('reg_register_role', that.data.token);

        //昵称
        app.register_info.nickname = register_info.nickname;
        wx.setStorageSync('reg_nickname', register_info.nickname)
        //手机号
        app.register_info.telephone = register_info.telephone;
        wx.setStorageSync('reg_telephone', register_info.telephone)
        //性别
        app.register_info.sex = register_info.sex;
        wx.setStorageSync('reg_sex', register_info.sex)
        //头像地址
        app.register_info.avatar_url = register_info.avatar_url;
        wx.setStorageSync('reg_avatar_url', register_info.avatar_url)
        //用户角色
        app.register_info.register_role = register_info.register_role;
        wx.setStorageSync('reg_register_role', register_info.register_role)
        //签名
        app.register_info.signature = register_info.signature;
        wx.setStorageSync('reg_signature', register_info.signature)
        //邀请码
        app.register_info.invite_code = register_info.invite_code;
        wx.setStorageSync('reg_invite_code', register_info.invite_code)
        //微信Id
        app.register_info.wxinfo_id = register_info.wxinfo_id;
        wx.setStorageSync('reg_wxinfo_id', register_info.wxinfo_id)

        that.updateTime();
      },
    })
  },



  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function(options) {
    if (!(options.token)){
      //没有option.token
      this.setData({
        token: wx.getStorageSync('token')
      })
    }else{
      this.setData({
        token: options.token
      })
    }
    
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function() {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function() {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function() {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function() {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function() {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function() {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function() {

  }
})